home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / gamesmaster / source / asm / sprites / agasprites.s next >
Encoding:
Text File  |  1996-09-08  |  6.4 KB  |  219 lines

  1. ;Sprite Example (AGA only)
  2. ;-------------------------
  3. ;This example contains four 64 pixel wide sprites, in high resolution.
  4. ;You can move sprite number 2 around with the mouse, notice how it
  5. ;appears behind number 1 and in front of 3 and 4.
  6. ;
  7. ;This demo also uses the LIST feature to initialise the four sprites.
  8. ;
  9. ;The LMB exits the demo.
  10.  
  11.     opt    o+,c+,d-
  12.  
  13.     INCLUDE    "exec/exec_lib.i"
  14.     INCLUDE    "games/games_lib.i"
  15.     INCLUDE    "games/games.i"
  16.  
  17. CALL    MACRO
  18.     jsr    _LVO\1(a6)
  19.     ENDM
  20.  
  21.     SECTION    "Sprites",CODE
  22.  
  23. ;===========================================================================;
  24. ;                             INITIALISE DEMO
  25. ;===========================================================================;
  26.  
  27. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  28.     move.l    ($4).w,a6
  29.     lea    GMS_Name(pc),a1
  30.     moveq    #$00,d0
  31.     CALL    OpenLibrary
  32.     move.l    d0,GMS_Base
  33.     beq.s    Error
  34.  
  35.     move.l    GMS_Base(pc),a6          ;Run this demo at a user-selected
  36.     CALL    SetUserPri               ;priority.
  37.  
  38.     lea    ScreenStruct(pc),a0      ;Initialise our screen for use.
  39.     CALL    Add_Screen
  40.     tst.l    d0
  41.     bne.s    Error
  42.  
  43.     CALL    Show_Screen              ;Show our screen.
  44.  
  45.     lea    SpriteList(pc),a1
  46.     CALL    Init_Sprite
  47.  
  48.     lea    Circle1(pc),a1
  49.     CALL    Update_Sprite
  50.     lea    Circle3(pc),a1
  51.     CALL    Update_Sprite
  52.     lea    Circle4(pc),a1
  53.     CALL    Update_Sprite
  54.  
  55.     moveq    #JPORT1,d0               ;Read from port 1
  56.     CALL    Read_Mouse               ;Initialise the port.
  57.  
  58. ;===========================================================================;
  59. ;                                MAIN LOOP
  60. ;===========================================================================;
  61.  
  62.     lea    Circle2(pc),a1
  63.  
  64. Loop:    moveq    #JPORT1,d0               ;Read from port 1
  65.     CALL    Read_Mouse               ;Go get mouse position.
  66.     move.w    d0,d1
  67.     asr.w    #8,d0
  68.     add.w    d0,SPR_XPos(a1)
  69.     ext.w    d1
  70.     add.w    d1,SPR_YPos(a1)
  71.  
  72.     CALL    Wait_OSVBL               ;Allow screen-switching.
  73.     CALL    Update_Sprite            ;Put Sparkie on the screen.
  74.  
  75.     btst    #MB_LMB,d0
  76.     beq.s    Loop
  77.  
  78. ;===========================================================================;
  79. ;                              RETURN TO DOS
  80. ;===========================================================================;
  81.  
  82. ReturnToDOS:
  83.     move.l    GMS_Base(pc),a6
  84.     lea    ScreenStruct(pc),a0
  85.     CALL    Delete_Screen            ;Give back screen memory etc.
  86. Error:    move.l    GMS_Base(pc),a1
  87.     move.l    ($4).w,a6
  88.     CALL    CloseLibrary
  89. Quit:    MOVEM.L    (SP)+,A0-A6/D1-D7
  90.     moveq    #$00,d0
  91.     rts
  92.  
  93. ;===========================================================================;
  94. ;                                  DATA
  95. ;===========================================================================;
  96.  
  97. GMS_Name:
  98.     dc.b    "games.library",0
  99.     even
  100. GMS_Base:
  101.     dc.l    0
  102.  
  103. SpriteList:
  104.     dc.l    "LIST"
  105.     dc.l    Circle1
  106.     dc.l    Circle2
  107.     dc.l    Circle3
  108.     dc.l    Circle4
  109.     dc.l    LISTEND
  110.  
  111. Circle1    dc.l    "SPV1",0          ;Structure version.
  112.     dc.w    0                 ;Bank Number 0.
  113.     dc.l    Gfx_Circle1       ;Ptr to graphic.
  114.     dc.w    20,20             ;Beginning X/Y position
  115.     dc.w    0                 ;Current frame.
  116.     dc.w    64                ;Width (16/32/64)
  117.     dc.w    64                ;Height
  118.     dc.w    16                ;Amt of colours.
  119.     dc.w    16                ;Colour start in palette.
  120.     dc.w    2                 ;Amt of planes.
  121.     dc.w    LORES             ;Attributes.
  122.     dc.w    0                 ;PlayField position.
  123.     dc.l    0,0               ;Private.
  124.  
  125. Circle2    dc.l    "SPV1",0          ;Structure version.
  126.     dc.w    2                 ;Bank Number 2.
  127.     dc.l    Gfx_Circle2       ;Ptr to graphic.
  128.     dc.w    70,70             ;Beginning X/Y position
  129.     dc.w    0                 ;Current frame.
  130.     dc.w    64                ;Width (16/32/64)
  131.     dc.w    64                ;Height
  132.     dc.w    16                ;Amt of colours.
  133.     dc.w    16                ;Colour start in palette.
  134.     dc.w    2                 ;Amt of planes.
  135.     dc.w    LORES             ;Attributes.
  136.     dc.w    0                 ;PlayField position.
  137.     dc.l    0,0               ;Private.
  138.  
  139. Circle3    dc.l    "SPV1",0          ;Structure version.
  140.     dc.w    4                 ;Bank Number 4.
  141.     dc.l    Gfx_Circle3       ;Ptr to graphic.
  142.     dc.w    120,120           ;Beginning X/Y position
  143.     dc.w    0                 ;Current frame.
  144.     dc.w    64                ;Width (16/32/64)
  145.     dc.w    64                ;Height
  146.     dc.w    16                ;Amt of colours.
  147.     dc.w    16                ;Colour start in palette.
  148.     dc.w    2                 ;Amt of planes.
  149.     dc.w    LORES             ;Attributes.
  150.     dc.w    0                 ;PlayField position.
  151.     dc.l    0,0               ;Private.
  152.  
  153. Circle4    dc.l    "SPV1",0          ;Structure version.
  154.     dc.w    6                 ;Bank Number 4.
  155.     dc.l    Gfx_Circle4       ;Ptr to graphic.
  156.     dc.w    170,170           ;Beginning X/Y position
  157.     dc.w    0                 ;Current frame.
  158.     dc.w    64                ;Width (16/32/64)
  159.     dc.w    64                ;Height
  160.     dc.w    16                ;Amt of colours.
  161.     dc.w    16                ;Colour start in palette.
  162.     dc.w    2                 ;Amt of planes.
  163.     dc.w    HIRES             ;Attributes.
  164.     dc.w    0                 ;PlayField position.
  165.     dc.l    0,0               ;Private.
  166.  
  167. AMT_PLANES =    1
  168.  
  169. ScreenStruct:
  170.     dc.l    "GSV1",0
  171.     dc.l    0,0,0             ;Screen_Mem1/2/3
  172.     dc.l    0                 ;Screen link.
  173.     dc.l    ScreenPalette     ;Address of the screen palette.
  174.     dc.l    0                 ;Address of a ColourList.
  175.     dc.l    32                ;Amt of colours in the palette.
  176.     dc.w    320,256,320,256   ;Screen & Pic Height/Width
  177.     dc.w    AMT_PLANES        ;Amt_Planes
  178.     dc.w    0,0               ;X/Y Top Of Screen
  179.     dc.w    0,0               ;X/Y Pic Offsets (for scrolling).
  180.     dc.l    SPRITES|NOSPRBDR  ;Special attributes.
  181.     dc.w    LORES|COL24BIT    ;Screen mode.
  182.     dc.b    INTERLEAVED       ;Screen type
  183.     dc.b    0                 ;Reserved.
  184.     even
  185.  
  186. ScreenPalette:
  187.     dc.l    $00000000,$000F0000,$001F0000,$002F0000
  188.     dc.l    $003F0000,$004F0000,$005F0000,$006F0000
  189.     dc.l    $007F0000,$008F0000,$009F0000,$00AF0000
  190.     dc.l    $00BF0000,$00CF0000,$00DF0000,$00EF0000
  191.     dc.l    $00FF0000,$00001111,$00002222,$00003333
  192.     dc.l    $00004444,$00005555,$00006666,$00007777
  193.     dc.l    $00008888,$00009999,$0000AAAA,$0000BBBB
  194.     dc.l    $0000CCCC,$0000DDDD,$0000EEEE,$0000FFFF
  195.  
  196. ;===========================================================================;
  197. ;                         ALL CHIP RAM DATA HERE
  198. ;===========================================================================;
  199.  
  200.     SECTION    "Graphics",DATA_C
  201.  
  202.     CNOP    0,4    ;Sprite must be 64bit aligned.
  203. Gfx_Circle1:
  204.     INCBIN    "GAMESLIB:data/CircleSpr1.raw"
  205.  
  206.     CNOP    0,4    ;Sprite must be 64bit aligned.
  207. Gfx_Circle2:
  208.     INCBIN    "GAMESLIB:data/CircleSpr2.raw"
  209.  
  210.     CNOP    0,4    ;Sprite must be 64bit aligned.
  211. Gfx_Circle3:
  212.     INCBIN    "GAMESLIB:data/CircleSpr3.raw"
  213.  
  214.     CNOP    0,4    ;Sprite must be 64bit aligned.
  215. Gfx_Circle4:
  216.     INCBIN    "GAMESLIB:data/CircleSpr3.raw"
  217.  
  218.  
  219.